package com.wswy.wzcx.ui.adapter;

import android.graphics.Rect;
import android.os.Parcelable;
import android.view.View;
import android.view.ViewGroup;

import com.che.libcommon.recycler.Component;
import com.che.libcommon.recycler.RowFactory;
import com.che.libcommon.recycler.RowListAdapter2;
import com.che.libcommon.recycler.RowViewHolder;
import com.wswy.wzcx.model.JZCFMode;
import com.wswy.wzcx.ui.component.JZCFComponent;
import com.wswy.wzcx.ui.component.JZCFComponent2;

/**
 * Created by wangduheng26 on 2018/3/6.
 * wangduheng26@gmail.com
 */

public class JZCFAdapter extends RowListAdapter2<Parcelable> {
    boolean editMode;

    public JZCFAdapter() {
        super(Rect.class, new RowFactory<Rect>() {
            @Override
            public Component<Rect> create(ViewGroup parent) {
                return new JZCFComponent2(parent);
            }
        });
    }


    @Override
    public void onBindViewHolder(RowViewHolder<Parcelable> holder, int position) {
        Component<? extends Parcelable> component = holder.getComponent();
        if (component instanceof JZCFComponent) {
            ((JZCFComponent) component).editMode(editMode);
        }
        super.onBindViewHolder(holder, position);

    }

    public void setEditMode(){
        editMode=true;
        notifyDataSetChanged();
    }

    public void exitEditMode() {
        editMode = false;
        notifyDataSetChanged();
    }

    public boolean getMode() {
        return editMode;
    }

    @Override
    protected void fireOnItemClickedEvent(View view, int position) {
        if(!editMode){
            super.fireOnItemClickedEvent(view, position);
        }
    }
}
